package com.zmz.lambda;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * Create with IntelliT IDEA
 *
 * @Author: zhengmingzhe
 * @Date: 2022/07/30/20:17
 * @Description:  使用lambda进行集合排序
 */
public class Lambda08 {
    public static  void main(String [] args) {
        List<Item2> list = new ArrayList<>();
        list.add(new Item2(1, "阿萨", 10.22));
        list.add(new Item2(2, "撒旦", 20.21));
        list.add(new Item2(3, "答案", 22.22));


//        Collections.sort(list, new Comparator<Item2>() {
//            @Override
//            public int compare(Item2 o1, Item2 o2) {
//                return (int)(o1.getPrice()-o2.getPrice());
//            }
//        });
        list.forEach(t->System.out.println(t));

        Collections.sort(list,(a,b)->(int)(a.getPrice()-b.getPrice()));
        list.forEach(t->System.out.println(t));
    }
}
